package com.hy.admin.security.config;

import java.util.HashMap;
import java.util.Map;

import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.hy.admin.security.utils.CommonResult;

/**
 * 说明： 自定义授权异常
 */
@JsonSerialize(using = CustomOAuth2ExceptionSerializer.class)
public class CustomOAuth2Exception extends OAuth2Exception{
	
	private static final long serialVersionUID = 1L;
	
	CommonResult result;
	
	public CustomOAuth2Exception(String msg) {
		super(msg);
		result = new CommonResult();
		result.setCode(getHttpErrorCode());
		result.setMsg(msg);
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("error", result.getCode());
		map.put("message", msg);
		
		result.setData(map);
	}

	public CustomOAuth2Exception(Integer code, String msg) {
		this(msg);
		result.setCode(code);
	}
	
	public CommonResult getResult() {
		return result;
	}
	
}
